package com.km.team.phsystem.service.impl;

import cn.hutool.core.date.DateUtil;
import com.km.team.phsystem.beans.pojo.TemporaryAppointment;
import com.km.team.phsystem.beans.pojo.TemporaryAppointmentExample;
import com.km.team.phsystem.common.utils.LocalDateUtil;
import com.km.team.phsystem.service.IQueueService;
import com.km.team.phsystem.service.QueueNumberAssistService;
import com.km.team.phsystem.service.TemporaryAppointmentService;
import com.km.team.phsystem.service.TimeSlotPhConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @author ：Riven.
 * @description：
 * @date ：2018/12/6
 */
@Service("queueNumberAssistService")
public class QueueNumberAssistServiceImpl implements QueueNumberAssistService {

    private final TimeSlotPhConfigService timeSlotPhConfigService;
    private final IQueueService queueService;
    private final TemporaryAppointmentService temporaryAppointmentService;

    @Autowired
    public QueueNumberAssistServiceImpl(TimeSlotPhConfigService timeSlotPhConfigService, IQueueService queueService,
                                        TemporaryAppointmentService temporaryAppointmentService) {
        this.timeSlotPhConfigService = timeSlotPhConfigService;
        this.queueService = queueService;
        this.temporaryAppointmentService = temporaryAppointmentService;
    }

    /**
     * 校验是否可以排号
     *
     * @param businessId 业务ID
     * @param date       日期
     * @param timeSlotId 时段ID
     * @return
     */
    @Override
    public Boolean queueNumCheck(String businessId, String date, String timeSlotId) {

        //获取该业务类型下该时段的受理数量
        Integer timeNum =
            this.timeSlotPhConfigService.getAcceptancesNumForBusinessIdAndTimeSlotId(timeSlotId);
        //查询队列里面的排队情况
        Long aLong = this.queueService.selectQueueNumFotBusinessIdAndDateAndTimeSlot(Integer.valueOf(businessId),
            LocalDateUtil.stampToDate(date), Integer.valueOf(timeSlotId));
        return aLong >= timeNum;
    }


}
